package com.user.service;

import com.user.dao.UserDao;
import com.user.entity.User;
import com.user.util.CommonResponse;
import com.user.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    UserDao userDao;
    @Autowired
    TokenUtil tokenUtil;

    public CommonResponse login(User user){
        List<User> select = userDao.select(user);
        if(!select.isEmpty()){
            System.out.println(select.get(0).getId());
            String s = tokenUtil.generateToken(select.get(0).getId());
            return new CommonResponse(200,"ok",s);
        }
        else
            return new CommonResponse(500,"false");
    }
    public CommonResponse register(User user){

        int in = userDao.insert(user);
        if(in != 0)
            return new CommonResponse(200,"ok");
        else
            return new CommonResponse(500,"false");

    }
}
